package cn.dinkevin.xui.listener;

import android.view.View;

/**
 * 双击事件
 * Created by WuFei on 2017/5/4.
 * Copyright ©2017 juziwl, All Rights Reserved.
 */
public abstract class MultiClickListener implements View.OnClickListener {

    private static final long DOUBLE_CLICK_TIME_DELTA = 300;//双击最长间隔毫秒
    long lastClickTime = 0;

    @Override
    public void onClick(View v) {
        long clickTime = System.currentTimeMillis();
        if (clickTime - lastClickTime < DOUBLE_CLICK_TIME_DELTA){
            onDoubleClick(v);
        } else {
            onSingleClick(v);
        }
        lastClickTime = clickTime;
    }

    public abstract void onSingleClick(View v);
    public abstract void onDoubleClick(View v);
}
